<?
function kirim(){
	global $inp_par,$inp;
        $sql = "select * from m_leveransir where id_leveransir='$inp[id_leveransir]'";
	$res = dbresult($sql);
	$r = pg_fetch_array($res);
	echo "<form name=account action=\"?".var_kirim($inp_par)."\" method=post>
			<input type=hidden name=inp[id_leveransir] value='$r[id_leveransir]'>
                        <input type=hidden name=inp[nama_leveransir] value='$r[nama_leveransir]'>
                        <input type=hidden name=inp[npwp_leveransir] value='$r[npwp_leveransir]'>
                        <input type=hidden name=inp[alamat_leveransir] value='$r[alamat_leveransir]'>
			</form>";
	echo "<script>Send();</script>";
}

function lihat(){
	global $inp_par,$inp;
	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr> 
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr> 
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-rekanan1.gif\" height=\"25\"></td>
		</tr>
		</table>

                <!--<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"hitam\">
		<tr class=\"tbltagihan\">
		<td><input type=\"button\" name=\"Submit222222\" value=\"Input Baru\" class=\"tombolgo\" onclick=window.location=\"javascript:Start('rekanan.php?inp_par[mode]=add','650','500')\"></td>
		</tr>
		</table>-->
                <form name=\"form2\" method=\"post\" action=\"?".var_kirim($inp_par)."\">
		<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"hitam\">
		<tr class=\"tbltagihan\">
		<td>&nbsp;Search :&nbsp;</td>
		<td> <input name=\"inp_par[kata]\" type=\"text\" class=\"form1\" size=\"30\" value=\"$inp_par[kata]\"> </td>
		<td>&nbsp; <input type=\"submit\" name=\"Submit\" value=\"GO &raquo;\" class=\"tombolgo\">&nbsp;</td>
		</tr>
		</table>
                <table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td><a href=\"pilih-customer.php?".var_kirim($inp_par)."\" class=\"menuppnaktif\">DAFTAR REKANAN</a></td>
		<td width=\"2\"><img src=\"../img/0.gif\" width=\"2\" height=\"1\"></td>
		<td><a href=\"pilih-customer.php?inp_par[mode]=add".var_kirim($inp_par)."\" class=\"menuppn\">INPUT REKANAN</a></td>
		</tr>
		</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
		<tr class=\"tbltagihan\"> 
		<td width=\"30\"> <div align=\"center\">No</div></td>
		<td width=\"30\"><div align=\"center\">Kode</div></td>
		<td><div align=\"center\">Nama Rekanan</div></td>
                <td width=\"30\"><div align=\"center\">NPWP Rekanan</div></td>
                <td><div align=\"center\">Alamat Rekanan</div></td>
		</tr>";
	$search=" (lower(id_leveransir) like '%".strtolower($inp_par[kata])."%' or lower(nama_leveransir) like '%".strtolower($inp_par[kata])."%' or lower(npwp_leveransir) like '%".strtolower($inp_par[kata])."%')";
        $sql="select * from m_leveransir where $search  order by nama_leveransir asc";
	$arr_tabel=definisi_halaman($sql);
	$result=$arr_tabel["res_sql"];
	$i=1+$inp_par[awalan]*$inp_par[jumlah_per_hal];
	while($r=pg_fetch_array($result)){
		$warna=$warna=="#E3F1FC"?"#F4FAFF":"#E3F1FC";
		$txtout.="<tr onmouseover=\"this.style.backgroundColor='#FDFFDD';\" style=\"background-color: $warna;\" onmouseout=\"this.style.backgroundColor='$warna';\">
			<td><div align=\"center\"><input type=radio name=inp[id_leveransir] value='$r[id_leveransir]'></div></td>
			<td>$r[id_leveransir]</td>
			<td>$r[nama_leveransir]</td>
                        <td>$r[npwp_leveransir]</td>
                        <td>$r[alamat_leveransir]</td>
			</tr>";
		$i++;
	}

	$txtout.="</table>
		</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tbltagihan\">
		<tr>
		<td>&nbsp;<input type=\"submit\" name=\"inp[aksi]\" value=\"Ok &raquo;\" class=\"tomboladd\">
		<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tomboladd\" onClick=\"window.close();\">
		</td>
		<td>
		$arr_tabel[tabel_halaman]
		</td>
		</tr>
		</table>
		</form>";
	return $txtout;
}

function form(){
	global $inp_par, $inp, $permisi, $sql_tambahan, $kode;

	//Start Load Data//
        $id_leveransir = kdauto("m_leveransir","LV");
	if ($inp_par[mode]=="edit"){
		$sql2="select * from m_leveransir where id_leveransir='$inp_par[id_leveransir]'";
		$result2 = dbresult($sql2);//cho $sql2;
		$r = pg_fetch_array($result2,0);
	}

        //Start Check Validasi//
        $r[id_leveransir] = $r[id_leveransir] == ""? $id_leveransir: $r[id_leveransir];
        $r[nama_leveransir] = $inp[nama_leveransir] == ""? $r[nama_leveransir]: $inp[nama_leveransir];
        $r[npwp_leveransir] = $inp[npwp_leveransir] == ""? $r[npwp_leveransir]: $inp[npwp_leveransir];
//        $arr=split("-",str_replace(".","-",$r[npwp_leveransir]));
//        $arr[0] = $inp[npwp1] == ""? $arr[0]: $inp[npwp1];
//        $arr[1] = $inp[npwp2] == ""? $arr[1]: $inp[npwp2];
//        $arr[2] = $inp[npwp3] == ""? $arr[2]: $inp[npwp3];
//        $arr[3] = $inp[npwp4] == ""? $arr[3]: $inp[npwp4];
//        $arr[4] = $inp[npwp5] == ""? $arr[4]: $inp[npwp5];
//        $arr[5] = $inp[npwp6] == ""? $arr[5]: $inp[npwp6];
        $r[alamat_leveransir] = $inp[alamat_leveransir] == ""? $r[alamat_leveransir]: $inp[alamat_leveransir];


        generate_rule("is_isi","inp[id_leveransir]","Anda Harus Mengisi ID Rekanan");
	generate_rule("is_isi","inp[nama_leveransir]","Anda Harus Mengisi Nama Rekanan");
	generate_rule("is_isi","inp[npwp_leveransir]","Anda Harus Mengisi No. NPWP");
        generate_rule("is_rangesd","inp[npwp_leveransir]","No. NPWP Tidak Lengkap & Harus Angka","0","15");
	generate_rule("is_isi","inp[alamat_leveransir]","Anda Harus Mengisi Alamat");

        $txtout=generate_validasi();
	//End Check Validasi//

	//End Load Data//
	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr>
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-rekanan1.gif\" height=\"25\"></td>
		</tr>
		</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td><a href=\"?".var_kirim($inp_par,"mode")."\" class=\"menuppn\">DAFTAR REKANAN</a></td>
		<td width=\"2\"><img src=\"../img/0.gif\" width=\"2\" height=\"1\"></td>
		<td><a href=\"?inp_par[mode]=add".var_kirim($inp_par)."\" class=\"menuppnaktif\">INPUT REKANAN</a></td>
		</tr>
		</table>
                <form name=form1 method=\"post\" action=\"?".var_kirim($inp_par)."\" onSubmit=\"return validasi(document.form1);\">
		<table width=98% border=0 align=center cellpadding=3 cellspacing=1 bgcolor=\"C6E6FF\" class=tabel1>
		<tr class=\"tbltagihan\">
		<td colspan=\"3\">Form Input Daftar Rekanan</td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>1.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">KODE REKANAN</td>
		<td bgcolor=\"#FFFFFF\"><input name=\"inp[id_leveransir]\" type=\"text\" class=\"form2\" size=\"10\" value=\"".trim($r["id_leveransir"])."\" maxlength=10 disabled>
                    <input name=\"inp[id_leveransirH]\" type=\"hidden\" class=\"form2\" size=\"15\" value=\"".trim($r["id_leveransir"])."\" maxlength=10></td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>2.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">NAMA REKANAN</td>
		<td><input onkeyup=\"ToUpper(this)\" name=\"inp[nama_leveransir]\" type=\"text\" class=\"form2\" size=\"60\" value=\"".trim($r["nama_leveransir"])."\"></td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>3.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">NO. NPWP</td>
		<td><input name=\"inp[npwp_leveransir]\" type=\"text\" class=\"form2\" size=\"20\" value=\"".trim($r["npwp_leveransir"])."\" maxlength=15></td></td>
		</tr>";

	$txtout.="<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>4.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">ALAMAT</td>
		<td bgcolor=\"#FFFFFF\"><textarea input name=\"inp[alamat_leveransir]\" type=\"text\" class=\"form2\" cols=\"60\" rows=\"2\" value=\"".trim($r["alamat_leveransir"])."\">".trim($r["alamat_leveransir"])."</textarea>
		</td>
		</tr>
		";
	$txtout.="<tr bgcolor=\"#FFFFFF\">
		<td colspan=\"3\"> <div align=\"center\">";
        if($permisi["add"]=="izin"){
            $txtout.="<input type=\"submit\" name=\"inp[aksi]\" value=\"Save &raquo;\" class=\"tombolgo\">";
        }
	$txtout.="<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tombolgo\" onClick=\"javascript:history.back()\">
		</div></td>
		</tr>
		</table>
		</form>";
	return $txtout;

}

function tambah(){
	global $inp,$inp_par,$inp_cook,$cnama;
//	$npwp=$inp[npwp1].".".$inp[npwp2].".".$inp[npwp3].".".$inp[npwp4]."-".$inp[npwp5].".".$inp[npwp6];
	$sql_cek = "select npwp_leveransir from m_leveransir where npwp_leveransir = '".trim($inp[npwp_leveransir])."' limit(1)";
	$res_cek = dbresult($sql_cek);
	$r_cek = pg_num_rows($res_cek);

	if((int)$r_cek < 1){
			$sql="insert into m_leveransir (id_leveransir,nama_leveransir,npwp_leveransir,alamat_leveransir,entry_date,entry_by,update_date,update_by,entry_ip,update_ip)values('".trim($inp[id_leveransirH])."','".trim($inp[nama_leveransir])."', '".trim($inp[npwp_leveransir])."', '".trim($inp[alamat_leveransir])."','".e_getDateNow()."','".$cnama."','".e_getDateNow()."','".$cnama."','".e_getIpAddr()."','".e_getIpAddr()."')";
//                        echo $sql;
			dbresult($sql);
			echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";

	}else{
		echo "<script>alert('NPWP sudah ada Di Database.. !!')</script>";
                echo "<script>window.history.back();</script>";
	}

}

function generate_form($inp_par){
	global $inp;
	switch ($inp_par[mode]) {
                case "add":
                        $txtout.=$inp[aksi]==""?form():tambah();
		break;
		case "lihat":
			$txtout.=$inp[aksi]==""?lihat():kirim();
		break;
		default:
                        $txtout.=$inp[aksi]==""?lihat():kirim();
		break;
	}
	return $txtout;
}
?>
